<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends MY_Controller {

	public function index() {
		$this->load->view('page-index');
	}

	public function hotel() {
		$data['option_cities'] 		= $this->option_encode($this->hotel->get_location_data());
		$data['option_sliders'] 	= $this->href_encode($this->hotel->get_promo_slider());
		$this->load->view('hotel', $data);
	}

	public function search_hotel() {
		// Start SESSION untuk halaman ini
		session_start();

		$checkin 	                = $this->input->get('check-in');
		$checkout 	                = $this->input->get('check-out');
		$adult 		                = $this->input->get('adult');
		$children 	                = $this->input->get('children');
		$location					= $this->input->get('location');
		$arrayLoc					= explode(" ", $location);
		$city_code 					= $arrayLoc[count($arrayLoc)-1];
		$searched_hotel				= $this->hotel->get_searched_hotel($checkin, $checkout, $adult, $children,$city_code);

		$data['option_cities'] 		= $this->option_encode($this->hotel->get_location_data());
		$data['searched_hotels'] 	= $this->search_encode($searched_hotel);
		$data['hotel_found'] 		= $this->hotel_found_encode($searched_hotel);

		/* Dari JSON hasil pencarian hotel di ambil bagian detail_pricesnya saja
		 * dengan method $this->get_detail_prices();
		 * Simpan array detail prices hotel pada session dengan key 'searched_hotel_detail_prices' */
		$_SESSION['searched_hotel_detail_prices'] = serialize($this->get_detail_prices($searched_hotel));

        // Simpan checkin/checkout date di session
        $_SESSION['checkin']        = $checkin;
        $_SESSION['checkout']       = $checkout;

		$this->load->view('search-hotel', $data);
	}

	public function hotel_details() {
		// Start SESSION untuk halaman ini
		session_start();

		// Ambil hotel code dari inputan GET
		$hotel_code               = $this->input->get('hotel_code');

		// Ambil detail prices hotel dari session;
		$searched_hotel 		  = unserialize($_SESSION['searched_hotel_detail_prices']);

        // Simpan htid di session;
        $_SESSION['htid']         = $searched_hotel["$hotel_code"]->HtId;

		// Menampilkan detail room
        $data['room_found']       = $this->room_encode($searched_hotel["$hotel_code"]);

        // Simpan price di session
        $_SESSION['hotel_price']  = $searched_hotel["$hotel_code"]->Price->Total;

        // untuk mengambil atribute hotel pada webservice
		$hotel_detail             = $this->hotel->get_hotel_attribut("$hotel_code");

        // Simpan nama hotel pada session
        $_SESSION['hotel_name']   = $hotel_detail->HotelName;

        // Menampilkan detail hotel
        $data['hotel_detail']     = $this->get_details_hotel($hotel_detail);

		$this->load->view('hotel-details', $data);
	}

    public function hotel_payment_details() {
        // Start SESSION untuk halaman ini
        session_start();

        // Ambil htid dari session;
        $hotel_id               = $_SESSION['htid'];

        // Ambil PNR dan simpan pada SESSION
        $pnr_hotel              = $this->hotel->get_pnr_hotel($hotel_id);
        $_SESSION['pnr_hotel']  = $pnr_hotel;

        // Ambil dari PNR, jumlah adult/children untuk form pada payment
        $tot_adult              = $pnr_hotel->Adult;
        $tot_child              = $pnr_hotel->Child;

        // Form untuk adult/children pada view
        $data['adult']          = $this->adult_form_encode($tot_adult);
        $data['children']       = $this->children_form_encode($tot_child);

        // Ambil price dari session
        $price_hotels           = unserialize($_SESSION['searched_hotel_detail_prices']);

        // Payment Info pada view
        $data['payment_info']   = $this->hotel_payment_encode(
            $_SESSION['hotel_name'], $tot_adult, $tot_child,
            $pnr_hotel->TotalRoom, $pnr_hotel->NightDuration,
            $_SESSION['checkin'], $_SESSION['checkout'], $_SESSION['hotel_price']);

        $data['htid']           = $hotel_id;
        $data['remark']         = $pnr_hotel->Remark;
        $data['total_pax']      = $pnr_hotel->TotalPax;
        $data['total_room']     = $pnr_hotel->TotalRoom;


        $this->load->view('hotel-payment-details', $data);
    }

    public function flight() {
		$this->load->view('flight');
	}

	public function search_flight() {
		$this->load->view('search-flight');
	}

	public function passenger_details() {
		$this->load->view('passenger-details');
	}

	public function my_orders() {
		$this->load->view('my-orders');
	}

	public function checkout_confirmation() {
        // Start SESSION untuk halaman ini
        session_start();

        $htid    = $_SESSION['htid'];

        $booking = $this->hotel->booking($htid, $this->input->post());

        $data['checkout_confirmation'] = $booking;

		$this->load->view('checkout-confirmation', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */